import 'package:flu_framework/res/colors.dart';
import 'package:flutter/material.dart';

class XDCourseTitleWidget extends StatelessWidget {
  ///标签文字
  final String? labelText;

  final Color? labelColor;
  ///标签样式
  final TextStyle? labelTextStyle;

  ///标题文字
  final String? titleText;

  ///标题样式
  final TextStyle? titleTextStyle;

  ///最大行数
  final int maxLines;

  ///间距宽度
  final double widthMargin;

  final EdgeInsets margin;

  const XDCourseTitleWidget({
    Key? key,
    this.labelText,
    this.labelColor = const Color(0xFFFAAB37),
    this.labelTextStyle,
    this.titleText,
    this.titleTextStyle,
    this.maxLines = 2,
    this.widthMargin = 4.0,
    this.margin = const EdgeInsets.all(0),
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: margin,
      child: RichText(
        maxLines: maxLines,
        overflow: TextOverflow.ellipsis,
        text: TextSpan(children: [
          if (labelText != null)
            WidgetSpan(
                child: Container(
              padding: EdgeInsets.symmetric(horizontal: 5.0),
              child: Text(labelText!,
                  style: labelTextStyle ??
                      TextStyle(fontSize: 12, color: Colors.white)),
              decoration: BoxDecoration(
                  color: labelColor!,
                  borderRadius: BorderRadius.only(topLeft: Radius.circular(4),bottomRight: Radius.circular(4))),
            )),

          if (labelText != null) //间距
            WidgetSpan(child: SizedBox(width: widthMargin ?? 4.0)),

          //标题
          TextSpan(
            text: titleText ?? "",
            style:
                titleTextStyle ?? TextStyle(
                    fontSize: 14,
                    fontWeight: FontWeight.bold,
                    color: ZXColors.text_black_85),
          ),
        ]),
      ),
    );
  }
}
